﻿using System.Linq;
using Example.Model;
using Example.Transports.Order;
using Zero.Backend;

namespace Example.Handlers
{
    public class OrderHandler : IRequestHandler
    {
        public GetOrdersByCustomerResponse GetOrders(GetOrdersByCustomer request)
        {
            //using (var context = new ModelContext())
            //{
            //    var ord = new Order()
            //                  {
            //                      Cost = 300,
            //                      Owner = context.Customers.First(x => x.Id == request.CustomerId),
            //                      PlacedDate = DateTime.Now
            //                  };
            //    context.Orders.Add(ord);
            //    context.SaveChanges();
            //}

            using (var context = new ModelContext())
            {
                return new GetOrdersByCustomerResponse {Orders = context.Orders.Where(x=>x.Owner.Id == request.CustomerId).ToList()};
            }
        }
    }
}
